/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package perso;

import carte.Carte;
import ctrl.FactoryStarWars;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Benoît
 */
public abstract class PersonnageStarWars extends Personnage {

    static int nextID = 100;
    
    public PersonnageStarWars(int id, Carte carte) {
        super(id, carte);
    }

    @Override
    public void createPerso(ArrayList<Personnage> listPerso, int endPosX, int endPosY) {
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j <= 2; j++) {
                if (carte.getPerso()[(endPosX + 1) - i][(endPosY + 1) - j] == null) {
                    PersonnageStarWars newPerso;
                    if (endPosX == 1 && endPosY == 1) {
                        newPerso = new RebelPilot(nextID++, carte);
                    } else {
                        newPerso = new ImperialSoldier(nextID++, carte);
                    }
                    carte.getPerso()[(endPosX + 1) - i][(endPosY + 1) - j] = newPerso;
                    newPerso.px = (endPosX + 1) - i;
                    newPerso.py = (endPosY + 1) - j;
                    listPerso.add(newPerso);
                    return;
                }
            }
        }
    }

    @Override
    public boolean endOfGame(ArrayList<Personnage> listPerso) {
        boolean yoda = false;
        boolean darkvador = false;

        Iterator<Personnage> itr = listPerso.iterator();
        while (itr.hasNext()) {

            Personnage perso = itr.next();

            if (perso instanceof Yoda) {
                yoda = true;
            }
            if (perso instanceof DarkVador) {
                darkvador = true;
            }
        }
        if (!yoda || !darkvador) {
            return true;
        }
        return false;
    }
}
